OPEN
Section: MINTLIB LIBRARY FUNCTIONS
(3)
Updated: 3 March 1993
Index
Return to Main Contents
NAME
open - open or create a file for reading or writing
SYNOPSIS
#include <unistd.h>
#include <fcntl.h>
int open(const char *filename, int flags, ...);
DESCRIPTION
filename points to the pathname of a file. open opens the
named file for reading and/or writing, as specified by the
flags argument, and returns a descriptor for that file.
The flags argument may indicate the file is to be created if
it does not already exist (by specifying the O_CREAT flag).
In this case an extra integer parameter pmode is used; the
file is created with mode pmode as described in chmod and
modified by the process' umask value (see umask).
flags values are constructed by ORing flags from the following
list (one and only one of the first three flags below must
be used):
- O_RDONLY Open for reading only.
- O_WRONLY Open for writing only.
- O_RDWR Open for reading and writing.
- O_NDELAY Non-blocking I/O.
- O_SYNC Synchronize after writes (not implemented).
- O_APPEND If set, the seek pointer will be set to
the end of the file prior to each write.
- O_CREAT Create the file if it doesn't exist already.
- O_TRUNC If the file exists and is a regular file,
and the file is successfully opened using
O_RDWR or O_WRONLY, its length is truncated
to zero.
- O_EXCL If O_EXCL and O_CREAT are set, open will
fail if the file exists.
The seek pointer used to mark the current position within
the file is set to the beginning of the file.
The new descriptor is set to remain open across execve
system calls; see close and fcntl.
RETURN VALUES
open returns a non-negative file descriptor on success.
On failure, it returns -1 and sets errno to indicate the
error.
SEE ALSO
chmod(3),
close(3),
creat(3),
dup(3),
fcntl(3),
lseek(3),
read(3),
umask(3),
write(3)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 11:14:40 GMT, June 22, 2025